package customer

import (
	"context"
	pb "git.mycaigou.com/gfyx/micro-gfyx-user-service/proto/micro_gfyx_user_service_proto/micro-gfyx-user-service"
	"git.mycaigou.com/gfyx/micro-gfyx-user-service/service/customer"
	"git.myscrm.cn/golang/stark/v4"
)

type CustomerGroupServer struct {
	customerGroupService customer.CustomerGroupServiceIface
}

func NewCustomerGroupServer(customerGroupService customer.CustomerGroupServiceIface) pb.CustomerGroupServiceServer {
	return &CustomerGroupServer{customerGroupService: customerGroupService}
}

// GetCustomerGroupList 获取客群列表
func (c *CustomerGroupServer) GetCustomerGroupList(ctx context.Context, request *pb.GetCustomerGroupListRequest) (*pb.GetCustomerGroupListResponse, error) {
	var response = &pb.GetCustomerGroupListResponse{}
	response, err := c.customerGroupService.List(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "grpc GetCustomerGroupList err:%s", err.Error())
		return nil, err
	}
	return response, nil
}

func (c *CustomerGroupServer) SaveCustomerGroup(ctx context.Context, request *pb.SaveCustomerGroupRequest) (*pb.SaveCustomerGroupResponse, error) {
	var response = &pb.SaveCustomerGroupResponse{}
	response, err := c.customerGroupService.Save(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "grpc SaveCustomerGroup err:%s", err.Error())
		return nil, err
	}
	return response, nil
}

func (c *CustomerGroupServer) GetCustomerGroupDetail(ctx context.Context, request *pb.GetCustomerGroupDetailRequest) (*pb.GetCustomerGroupDetailResponse, error) {
	response, err := c.customerGroupService.Detail(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "grpc GetCustomerGroupDetail err:%s", err.Error())
		return nil, err
	}
	return response, nil
}

func (c *CustomerGroupServer) DeleteCustomerGroup(ctx context.Context, request *pb.DeleteCustomerGroupRequest) (*pb.DeleteCustomerGroupResponse, error) {
	response, err := c.customerGroupService.Delete(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "grpc DeleteCustomerGroup err:%s", err.Error())
		return nil, err
	}
	return response, nil
}
